package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.service.CreateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.regex.Pattern;

/**
 * @Author: Felix(李鑫)
 * @Date: 2020/8/29 11:03
 * @Description: 生成验证码
 */

@RestController
@RequestMapping("/creatCode")
public class CreatCodeController {

    @Autowired
    private CreateCodeService createCodeService;

    /**
     *  根据传来的手机号码和邮箱  生成验证码
     *
     * @param info
     * @return
     */
    @PostMapping("/validCode")
    public Result<String> createCode(String info) {

        //发送验证码
        boolean flag = createCodeService.sendCode(info);
        if (flag) {
            return new Result<>("success", "生成验证码成功");
        }
        return new Result<>("error", "输入的邮箱或手机号格式有误");
    }
}
